package file1;

import java.util.Scanner;

public class Homework {
    public static void main(String[] args) {
        //创建三个数组分别储存学生姓名、学号、年龄
        String student[] = new String[3];//储存学生对象
        int studentNumber[] = new int[3];//储存学生学号
        int age[]= new int[3];//储存学生年龄

        //录入信息
        Student(student,studentNumber,age);

        //判断学号是否唯一
        Judgment1(studentNumber);

        //判断id是否为2，为2的年龄+1
        Add(studentNumber,age);

        //遍历信息
        Traverse(student,studentNumber,age);

        //删除学生信息
        Delete(student,studentNumber,age);

    }

    //遍历各同学信息
    public static void Traverse(String student[],int studentNumber [],int age[]){
        for(int i=0;i<student.length;i++){
            System.out.println("第"+(i+1)+"个同学的姓名为:"+student[i]+" 学号为:"+studentNumber[i]+" 年龄为:"+age[i]);
        }
    }

    //创建一个类对姓名依次储存
    public static void Student(String person [],int array [],int day []){
        Scanner scan = new Scanner(System.in);
        for (int i=0;i<3;i++){
            System.out.println("请输入第"+(i+1)+"位同学姓名");
            person[i] = scan.nextLine();
        }
        for (int i=0;i<3;i++){
            System.out.println("请输入第"+(i+1)+"位同学学号");
            array[i] = scan.nextInt();
        }
        for (int i=0;i<3;i++){
            System.out.println("请输入第"+(i+1)+"位同学年龄");
            day[i] = scan.nextInt();
        }
    }

    //创建一个类判断学号是否唯一
    public static void Judgment1(int array[]){
        Scanner scan = new Scanner(System.in);
        for (int i=0;i<3-1;i++){
            for (int j=i+1;j<3;j++){
                if (array[i]==array[j]){
                    System.out.println("你输入的学号有错误，已有人使用此学号，请重新输入学号");
                    array[j] = scan.nextInt();
                }
            }
        }
    }

    //创建一个类判断学号是否存在
    public static void Delete(String student[],int studentNumber [],int age[]){
        Scanner scan = new Scanner(System.in);
        System.out.println("请输入想要删除的学生信息的学号");
        int id = scan.nextInt();
        boolean flag = true;
        for (int i=0;i< student.length;i++){
            if (id!=studentNumber[i]){
                flag = true;
            }else {
                flag = false;
                student[i] = null;
                studentNumber [i] = 0;
                age [i] = 0;
                break;
            }
        }
        if(flag==true){
            System.out.println("学号不存在，删除失败");
        }else {
            System.out.println("学号存在删除成功");
        }
        for (int i=0;i<student.length;i++){
            if (student[i]==null&&studentNumber[i]==0&&age[i]==0){
                continue;
            }
            System.out.println("学生姓名为："+student[i]+" 学号为："+studentNumber[i]+" 年龄为："+age[i]);
        }
    }

    //创建一个类使得学号id为2的年龄+1
    public static void Add(int studentNumber [],int age[]){
        for (int i = 0; i < 3; i++) {
            if (studentNumber[i]==2){
                age[i]+=1;
            }
        }
    }
}
